/**
 * Created with JetBrains WebStorm.
 * User: Eric
 * Date: 19/03/13
 * Time: 16:28
 * To change this template use File | Settings | File Templates.
 */

var Tile = require('../model/Tile.js');
var tileDao = require('../model/TileDao.js');

var building = require('../model/Building.js');
var buildingDao = require('../model/BuildingDao.js');
var objDumper = require('../Util/Dumper.js');
var PlantationDao = require('../model/PlantationDao.js');
var UserPlantationDao = require('../model/UserPlantationDao.js');
var MaturityDao = require('../model/MaturityDao.js');
var PersonageDao = require('../model/PersonageDao.js');
var HealthDao = require('../model/HealthDao.js');

var World = function World(){

}
World.prototype = {

    initialize : function() {
    },

    getMap : function(center, radius, callback){
        objDumper.dump(center);
        tileDao.findByCoordinates({min : center.x - radius, max : center.x + radius},
                                      {min : center.y - radius, max : center.y + radius},callback);
    },

    getTileSelected : function(id,callback){

        tileDao.findTileById({id : id}, function(tile){

            callback(tile);

        });

    },

    putPlant : function(s){

        UserPlantationDao.persistUserPlantation(s);

    },

    persistPerso : function(p){

        console.log("save");
        console.log(p);
        PersonageDao.persistPersonage(p,function(p){})

    },


    persistBuilding : function(building){


            buildingDao.persistBuilding({building : building});

    },

    persistUserPlantation : function(userPlantation,callback){

        UserPlantationDao.persistUserPlantation(userPlantation,callback);


    },

    getPlantations : function(callback){
        PlantationDao.getAll(callback);
    },

    getAllMaturity : function(callback){
        MaturityDao.findAllMaturity(callback);
    },

    getAllHealth : function(callback){
        HealthDao.findAll(callback);
    },

    findAllUserPlant : function(callback){

        UserPlantationDao.findAll(callback);


    },

    deletePlant : function(id){
        console.log("delete " + id);
        UserPlantationDao.deletePlantation(id);
    },

    putTile : function(tile){
        var oTile = new Tile();
        oTile.init(tile);
        tileDao.persistTile(oTile);
    }


}
module.exports = World;